package com.butterfly.domain.dao;

import java.util.List;

import javax.inject.Named;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.butterfly.domain.entity.Merchant;

@Named
public class MerchantDAOImpl extends AbstractDaoHibernate<Merchant> implements MerchantDAO {

	@Override
	protected Class<Merchant> getEntityClass() {
		return Merchant.class;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Merchant> findBy(Merchant searchCriteria) {
		Criteria criteria = getSession().createCriteria(Merchant.class);
		
		criteria.add(Restrictions.eq("enabled", searchCriteria.isEnabled()));
		
		if(searchCriteria.getCode() != null) {
			criteria.add(Restrictions.eq("code", searchCriteria.getCode())); 
		}
		
		if(searchCriteria.getName() != null) {
			criteria.add(Restrictions.eq("name", searchCriteria.getName()));
		}
		
		return criteria.list();
	}
	
	
}
